import random

def generate_matrix(rows, cols, prob=0.5):
    """生成 rows x cols 的 0/1 矩阵，prob 为 '1' 出现的概率"""
    matrix = [[str(int(random.random() < prob)) for _ in range(cols)] for _ in range(rows)]
    return matrix

def save_matrix(matrix, filename="input221.txt"):
    with open(filename, "w") as f:
        f.write(f"{len(matrix)} {len(matrix[0])}\n")
        for row in matrix:
            f.write("".join(row) + "\n")

if __name__ == "__main__":
    matrix = generate_matrix(10, 10, prob=0.4)  # 10x10 的矩阵，'1' 概率为 0.4
    save_matrix(matrix)
